1. Home
  2. Linux
  3. Linux Filters
  4. Linux – cut

Linux – cut

Linux cut command

The Linux cut command is a text processing command. This command is used to extract the specific column from a file. You need to define the column number and column delimiter with command.

Syntax:

cut -d<delemeter> -f<field1,field2,...> filename
  • -d This defines the deleter as coloumn seprator. Defaut column seprater is single space or tab.
  • -f Specify fields (column numbers) to fetch.

Example

Grep all usernames with there home directory created on a Linux system. The /etc/passwd file contained all users on a Linux system with other details. First filed of the file contains the username and 6’th filed contain the home directory of that user.

cut -d":" -f1,6 /etc/passwd

Fetch the column number 1,2,3,4 and 6. Here you can define a range using hyphen like 1-4.

cut -d":" -f1-4,6 /etc/passwd

You can also define multiple ranges with the single command.

cut -d":" -f1-3,5-7 /etc/passwd
Tags , ,